package com.work.demo.threaddemo;

import sun.misc.Unsafe;

import java.lang.reflect.Field;

/**
 * @ClassName : UnsafeInstance
 * @Description : 获取内存屏障类
 * @Author : LinYa
 * @Date: 2022/1/20  15:56
 */
public class UnsafeInstance {

	public static Unsafe reflectGetUnsafe(){
		try {
			Field field = Unsafe.class.getDeclaredField("theUnsafe");
			field.setAccessible(true);
			return (Unsafe) field.get(null);


		} catch (NoSuchFieldException | IllegalAccessException e) {
			e.printStackTrace();
		}
		return null;
	}
}
